import { Injectable } from '@angular/core';
import { BaseService } from "../../../core/service/base.service";
import { _HttpClient } from "@delon/theme";
import { Observable } from "rxjs";
import { catchError, tap } from "rxjs/operators";

@Injectable({
  providedIn: 'root'
})
export class DictionaryService extends BaseService{

  getUrl(): string {
    return "api/dict";
  }

  constructor(http: _HttpClient) {
    super(http);
  }

  getDictItem(dictCode: string): Observable<any> {
    const url = `${this.getUrl() + '/get-dict-item'}/${dictCode}`;
    return this.http.get<any>(url).pipe(
      tap(_ => this.log(`fetched object dictCode=${dictCode}`)),
      catchError(this.handleError<any>(`get dictItem dictCode=${dictCode}`)),
    );
  }

}
